﻿#ifndef APPCORE_H
#define APPCORE_H

#include <QAction>
#include <QToolBar>
#include <QUndoGroup>

class QActionArray
{
public:
    QActionArray() : m_type(""), m_action(nullptr) {}
    ~QActionArray()
    {
        qDeleteAll(m_childrenMap.values());
        if(m_action != nullptr)
            delete m_action;
    }
    QString m_type;
    QAction* m_action;
    QMap<QString, QActionArray*> m_childrenMap;
};

class AppCore : public QObject
{
    Q_OBJECT
public:

    static AppCore* getCore();
    static void releaseCore();

    // 添加全局action
    void insertAction(const QString& key, QAction *action);
    // 获取全局action
    QAction* getAction(const QString &key);

    // 添加全局工具条
    void insertToolBar(const QString& szKey, QToolBar *pToolBarObj);
    // 获取全局工具条
    QToolBar* getToolBar(const QString &szKey);

    void addUndoStack(QUndoStack* stack);
    void setActivityStack(QUndoStack* stack);

protected:
    explicit AppCore(QObject *parent = nullptr);

    void initUndoAction();

protected:
    // 单实例
    static  AppCore* m_core;
    // 全局action
    QActionArray m_actions;
    // 全局工具条
    QMap<QString, QToolBar*> m_toolBarMap;

    QUndoGroup* m_undoGroup;

};

#endif // APPCORE_H
